package com.ruoyi.web.controller.Tour;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.TourQuestion;
import com.ruoyi.system.service.ITourQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 问题管理Controller
 *
 * @author once
 * @date 2020-10-02
 */
@RestController
@RequestMapping("/Tour/question")
public class TourQuestionController extends BaseController
{
    @Autowired
    private ITourQuestionService tourQuestionService;

    /**
     * 查询问题管理列表
     */
    @PreAuthorize("@ss.hasPermi('Tour:question:list')")
    @GetMapping("/list")
    public TableDataInfo list(TourQuestion tourQuestion)
    {
        startPage();
        List<TourQuestion> list = tourQuestionService.selectTourQuestionList(tourQuestion);
        return getDataTable(list);
    }

    /**
     * 导出问题管理列表
     */
    @PreAuthorize("@ss.hasPermi('Tour:question:export')")
    @Log(title = "问题管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TourQuestion tourQuestion)
    {
        List<TourQuestion> list = tourQuestionService.selectTourQuestionList(tourQuestion);
        ExcelUtil<TourQuestion> util = new ExcelUtil<TourQuestion>(TourQuestion.class);
        return util.exportExcel(list, "question");
    }

    /**
     * 获取问题管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('Tour:question:query')")
    @GetMapping(value = "/{questionId}")
    public AjaxResult getInfo(@PathVariable("questionId") Long questionId)
    {
        return AjaxResult.success(tourQuestionService.selectTourQuestionById(questionId));
    }

    /**
     * 新增问题管理
     */
    @PreAuthorize("@ss.hasPermi('Tour:question:add')")
    @Log(title = "问题管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TourQuestion tourQuestion)
    {
        System.out.println(tourQuestion);
        return toAjax(tourQuestionService.insertTourQuestion(tourQuestion));
    }

    /**
     * 修改问题管理
     */
    @PreAuthorize("@ss.hasPermi('Tour:question:edit')")
    @Log(title = "问题管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TourQuestion tourQuestion)
    {
        return toAjax(tourQuestionService.updateTourQuestion(tourQuestion));
    }

    /**
     * 删除问题管理
     */
    @PreAuthorize("@ss.hasPermi('Tour:question:remove')")
    @Log(title = "问题管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{questionIds}")
    public AjaxResult remove(@PathVariable Long[] questionIds)
    {
        return toAjax(tourQuestionService.deleteTourQuestionByIds(questionIds));
    }
}
